package com.fyzk.activity.lottery.jc.beidan;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.tyjc.lottery.R;

import java.util.List;

/**
 * Created by fanxs11 on 2017/11/22.
 */

public class BeiDan_ZJQ_PayAdapter extends BeiDanBasePayAdapter {

    public BeiDan_ZJQ_PayAdapter(Context context, List<BeiDanChildBean> infors, OnBeiDanPayClickListerner listerner) {
        super(context, infors, listerner);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final BeiDanChildBean info = infors.get(i);
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.adapter_beidan_zjq_pay, null);
            holder.zhu = view.findViewById(R.id.beidan_pay_list_item_zhu);
            holder.delete = view.findViewById(R.id.beidan_pay_list_item_delete);
            holder.home = view.findViewById(R.id.beidan_pay_list_item_home);
            holder.vs = view.findViewById(R.id.beidan_pay_list_item_vs);
            holder.away = view.findViewById(R.id.beidan_pay_list_item_away);
            holder.week_num = view.findViewById(R.id.beidan_pay_list_matchnum);
            holder.zjq_0 = view.findViewById(R.id.beidan_pay_list_item_zjq_0);
            holder.zjq_1 = view.findViewById(R.id.beidan_pay_list_item_zjq_1);
            holder.zjq_2 = view.findViewById(R.id.beidan_pay_list_item_zjq_2);
            holder.zjq_3 = view.findViewById(R.id.beidan_pay_list_item_zjq_3);
            holder.zjq_4 = view.findViewById(R.id.beidan_pay_list_item_zjq_4);
            holder.zjq_5 = view.findViewById(R.id.beidan_pay_list_item_zjq_5);
            holder.zjq_6 = view.findViewById(R.id.beidan_pay_list_item_zjq_6);
            holder.zjq_7 = view.findViewById(R.id.beidan_pay_list_item_zjq_7);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.week_num.setText(info.getMatchNum()+"");
        holder.home.setText(info.getHomeTeam());
        holder.away.setText(info.getAwayTeam());

        holder.zjq_0.setText("0\n"+info.getScore_0());
        holder.zjq_1.setText("1\n"+info.getScore_1());
        holder.zjq_2.setText("2\n"+info.getScore_2());
        holder.zjq_3.setText("3\n"+info.getScore_3());
        holder.zjq_4.setText("4\n"+info.getScore_4());
        holder.zjq_5.setText("5\n"+info.getScore_5());
        holder.zjq_6.setText("6\n"+info.getScore_6());
        holder.zjq_7.setText("7+\n"+info.getScore_7());

        holder.zjq_0.setChecked(info.isScore_0);
        holder.zjq_1.setChecked(info.isScore_1);
        holder.zjq_2.setChecked(info.isScore_2);
        holder.zjq_3.setChecked(info.isScore_3);
        holder.zjq_4.setChecked(info.isScore_4);
        holder.zjq_5.setChecked(info.isScore_5);
        holder.zjq_6.setChecked(info.isScore_6);
        holder.zjq_7.setChecked(info.isScore_7);

        info.btnHGPojo.get(info.SCORE_0).isSel = info.isScore_0;
        info.btnHGPojo.get(info.SCORE_1).isSel = info.isScore_1;
        info.btnHGPojo.get(info.SCORE_2).isSel = info.isScore_2;
        info.btnHGPojo.get(info.SCORE_3).isSel = info.isScore_3;
        info.btnHGPojo.get(info.SCORE_4).isSel = info.isScore_4;
        info.btnHGPojo.get(info.SCORE_5).isSel = info.isScore_5;
        info.btnHGPojo.get(info.SCORE_6).isSel = info.isScore_6;
        info.btnHGPojo.get(info.SCORE_7).isSel = info.isScore_7;
        info.btnHGPojo.put(info.SCORE_0,info.btnHGPojo.get(info.SCORE_0));
        info.btnHGPojo.put(info.SCORE_1,info.btnHGPojo.get(info.SCORE_1));
        info.btnHGPojo.put(info.SCORE_2,info.btnHGPojo.get(info.SCORE_2));
        info.btnHGPojo.put(info.SCORE_3,info.btnHGPojo.get(info.SCORE_3));
        info.btnHGPojo.put(info.SCORE_4,info.btnHGPojo.get(info.SCORE_4));
        info.btnHGPojo.put(info.SCORE_5,info.btnHGPojo.get(info.SCORE_5));
        info.btnHGPojo.put(info.SCORE_6,info.btnHGPojo.get(info.SCORE_6));
        info.btnHGPojo.put(info.SCORE_7,info.btnHGPojo.get(info.SCORE_7));
        jiSuanZhuShu();

        holder.zjq_0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_0 = !info.isScore_0;
                if (info.isScore_0) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.zjq_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_1 = !info.isScore_1;
                if (info.isScore_1) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.zjq_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_2 = !info.isScore_2;
                if (info.isScore_2) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.zjq_3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_3 = !info.isScore_3;
                if (info.isScore_3) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.zjq_4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_4 = !info.isScore_4;
                if (info.isScore_4) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.zjq_5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_5 = !info.isScore_5;
                if (info.isScore_5) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.zjq_6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_6 = !info.isScore_6;
                if (info.isScore_6) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.zjq_7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.isScore_7 = !info.isScore_7;
                if (info.isScore_7) {
                    info.checkNum++;
                } else {
                    info.checkNum--;
                }
                jiSuanZhuShu();
            }
        });

        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                info.clearAll();
                infors.remove(info);
                notifyDataSetChanged();
                if (infors.size() == 0) {
                    jiSuanZhuShu();
                }
            }
        });

        return view;
    }

    @Override
    protected void jiSuanZhuShu() {

        if (listerner != null) {
            listerner.onItemClick();
        }
    }

    class ViewHolder {
        LinearLayout zhu;
        LinearLayout delete;
        TextView home;
        TextView week_num;
        TextView vs;
        TextView away;
        CheckBox zjq_0;
        CheckBox zjq_1;
        CheckBox zjq_2;
        CheckBox zjq_3;
        CheckBox zjq_4;
        CheckBox zjq_5;
        CheckBox zjq_6;
        CheckBox zjq_7;

    }
}
